ARG SOLR_VERSION=8.5.1
FROM solr:${SOLR_VERSION}

USER root:root

ARG TZ=Asia/Shanghai
ENV TZ ${TZ}

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && sed -i -e "s/UTC/UTC+8/g" /opt/solr/bin/solr \
    && curl -L -o /opt/solr/server/solr-webapp/webapp/WEB-INF/lib/ik-analyzer-8.3.0.jar "https://search.maven.org/remotecontent?filepath=com/github/magese/ik-analyzer/8.3.0/ik-analyzer-8.3.0.jar"

ARG WEBINFPATH=/opt/solr/server/solr-webapp/webapp/WEB-INF
ADD ik/ext.dic $WEBINFPATH
ADD ik/IKAnalyzer.cfg.xml $WEBINFPATH
ADD ik/stopword.dic $WEBINFPATH


ARG SOLR_DATAIMPORTHANDLER_MYSQL=false
ENV SOLR_DATAIMPORTHANDLER_MYSQL ${SOLR_DATAIMPORTHANDLER_MYSQL}

# download mysql connector for dataimporthandler
RUN if [ ${SOLR_DATAIMPORTHANDLER_MYSQL} = true ]; then \
    curl -L -o /tmp/mysql_connector.tar.gz "https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.45.tar.gz" \
    && mkdir /opt/solr/contrib/dataimporthandler/lib \
    && tar -zxvf /tmp/mysql_connector.tar.gz -C /opt/solr/contrib/dataimporthandler/lib "mysql-connector-java-5.1.45/mysql-connector-java-5.1.45-bin.jar" --strip-components 1 \
    && rm /tmp/mysql_connector.tar.gz \
    ;fi

ARG SOLR_DATAIMPORTHANDLER_MSSQL=false
ENV SOLR_DATAIMPORTHANDLER_MSSQL ${SOLR_DATAIMPORTHANDLER_MSSQL}

# download mssql connector for dataimporthandler
RUN if [ ${SOLR_DATAIMPORTHANDLER_MSSQL} = true ]; then \
    curl -L -o /tmp/mssql-jdbc-7.0.0.jre8.jar "https://github.com/Microsoft/mssql-jdbc/releases/download/v7.0.0/mssql-jdbc-7.0.0.jre8.jar" \
    && mkdir -p /opt/solr/contrib/dataimporthandler/lib \
    && mv /tmp/mssql-jdbc-7.0.0.jre8.jar "/opt/solr/contrib/dataimporthandler/lib/mssql-jdbc-7.0.0.jre8.jar" \
    ;fi


CMD [ "solr-foreground","-force" ]